"""
!!! Осторожно, виснет комп минут на 5 !!!
6)
https://habr.com/ru/articles/825206/
Подсчет частот слов
"""
import gzip
import time

freqs = {}

with gzip.open('googlebooks-eng-all-1gram-20120701-a.gz', 'rb') as f:
    lines = f.read().decode('utf-8').splitlines()

    start = time.time()
    for line in lines:
        data = line.split('\t')
        word = data[0]
        count = int(data[2])
        if word in freqs:
            freqs[word] = freqs[word] + count
        else:
            freqs[word] = count

    print(f"Aardvark встречается {freqs['Aardvark']} раз.")
    end = time.time()

print(f'{end-start:.4f}')
